#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<errno.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h> 
#include<pthread.h>


int
main(void)
{
	char* path = "text.txt";
	int fd;	

	if((fd = open(path, O_RDWR | O_TRUNC |O_CREAT, 0755)) < 0){
		perror("open faild");
		exit(0);
	}
	
	char buffer[1024];
	int n_r;

	if((n_r = read(STDIN_FILENO, buffer, 10)) < 0){
		perror("read failed");
	}
	int n_w;
	if((n_w = write(fd, buffer, n_r)) < 0){
		perror("write faild");
	}
	
	struct stat stbuf;
	
	if(stat(path, &stbuf) < 0){
		perror("get stat faild");
	}

	printf("file size is %d\n",stbuf.st_size);
	
	printf("after truncate\n");

	if(truncate(path, stbuf.st_size + 10) < 0)
		perror("tuncate failed");

	if(stat(path, &stbuf) < 0){
		perror("get stat faild");
	}

	printf("file size is %d\n",stbuf.st_size);
	



	return 0;
	
}
